package cn.tedu.car.backend.order.service.impl;

import cn.tedu.car.backend.order.mapper.OrderMapper;
import cn.tedu.car.backend.order.service.OrderService;
import cn.tedu.car.backend.order.pojo.dto.OrderParam;
import cn.tedu.car.backend.order.pojo.dto.OrderQuery;
import cn.tedu.car.backend.order.pojo.po.RentOrderPO;
import cn.tedu.car.backend.order.pojo.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Slf4j

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderMapper  orderMapper;

    @Override
    public void saveOrder(OrderParam orderParam) {
        log.debug("插入{}",orderParam);
        RentOrderPO rentOrderPO =new RentOrderPO();
        BeanUtils.copyProperties(orderParam, rentOrderPO);
        rentOrderPO.setOrderNo(UUID.randomUUID().toString().replace("-",""));
        rentOrderPO.setCreateTime(new Date());
        orderMapper.insert(rentOrderPO);
    }

    @Override
    public List<OrderVO> selectOrder(OrderQuery orderQuery) {
        List<OrderVO> list = orderMapper.selectOrder(orderQuery);
        return list;
    }

    @Override
    public void updateOrder(OrderParam orderParam) {
        if (orderParam.getOrderNo() == null) {
            return;
        }
        RentOrderPO rentOrderPO =new RentOrderPO();
        BeanUtils.copyProperties(orderParam, rentOrderPO);
        log.debug("更新{}", rentOrderPO);
        orderMapper.update(rentOrderPO);
    }


}

